#__Author__  = white
import hashlib,os
from FTP_client.conf import settings
import  global_manage

def login(func):

    def wrapper(*args,**kwargs):
        record = 0
        while record <3:
            username = input("username: ")
            password = input("password: ")
            h = hashlib.md5()
            h.update(password.encode())
            hpasswd = h.hexdigest()
            f = open(settings.auth_file,'r')
            pass_dic = eval(f.readlines()[0])
            if username in pass_dic and pass_dic[username] == hpasswd:
                print("验证通过")
                global_manage._init()
                current_path = settings.root_catalog+'/'+username
                global_manage.set_value('current_path', current_path)
                global_manage.set_value('username', username)


                func(*args,**kwargs)

            else:
                print("error ,please retry")
                record+=1
                continue

        else:
            print("error")
            exit()


    return wrapper